<template>
	<view class="community">
		<view class="uni_header"></view>
		<view class="operating_box" style="margin-top:-80rpx;padding-top:20rpx;">
			<view class="cu-form-group" style="border-bottom:2rpx dotted grey;">
				<view class="title">绑定手机</view>
				<input placeholder="请输入绑定手机" v-model="sjhm" @input="getinputvalue" name="input"></input>
			</view>
			<view class="cu-form-group" style="border-bottom:2rpx dotted grey;">
				<view class="title">账户权限</view>
				<view @tap="setnewAuth">点击设置<text class="cuIcon-right"></text></view>
			</view>
			<view class="text-center margin-top-sm">
				<button style="width: 160rpx;" class="cu-btn bg-blue" @tap="addnewinfo">保存</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checkvalue:'',
				checkguid:'',
				sjhm:'',
				type:""
			};
		},
		onLoad(options) {
			this.checkvalue=options.value;
			this.checkguid=options.checkguid;
			let phone=options.sjhm;
			if(phone){
				this.sjhm=phone;
			}
		},
		methods: {
			setnewAuth() {
				console.log("新增手机号码"+this.sjhm)
				uni.navigateTo({
					url:"/pages/community/commaccount/setauth?phone="+this.sjhm+"&type=1"
				})
			},
			//获取输入 手机号码
			getinputvalue: function(event) {
				this.sjhm = event.target.value  
			}, 
			addnewinfo(){
				if(this.sjhm=='' || this.sjhm==null){
					uni.showToast({
						icon: 'none',
					    title: '请输入绑定手机'
					});
					return;
				}
				this.save(this.sjhm);
			},
			save(sjhm){
				let that=this;
				that.http.tokenreq({
					url:"subaccount/v1/savesub",
					data:{
						"phone_number":sjhm,
						"menu_code":this.checkvalue,
						"residential_quarters_guid":this.checkguid,
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						uni.showModal({
							content: e.message,
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									uni.redirectTo({
										url:"/pages/community/commaccount/commaccount"
									})
								}
							}
						});
					}else{
						uni.showToast({
							icon: 'none',
						    title: e.message
						});
					}
				})
			},
		}
	}
</script>

<style>
	.uni_header{
		height:120rpx;
	}
	.operating_header_text{
		color: #000000;
	}
	.foot{
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
	}
</style>
